﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NHibernate;
using schedulelist.ORM.dao.classes;
using schedulelist.ORM.dao.interfaces;
using schedulelist.ORM.mapping;
using schedulelist.ORM.dao;
using schedulelist.ORM.domain;

namespace schedulelist
{
    public partial class Login : System.Web.UI.Page
    {
        public static string CurrentUser="";
        public static string CurrentLog = "";
        protected void Page_Load(object sender, EventArgs e){}

        //обработчик нажатия на "Enter"
        protected void ent(object sender, EventArgs e) {
            Session["hbmsession"] = SiteMaster.openSession("localhost", "kurs", "root", "mysql");
            ISession session = (ISession)Session["hbmsession"];
            DAOFactory factory = new NHibernateDAOFactory(session);
            IUserDAO UsrDAO = factory.getUserDAO();
            //Получаем введенные логин и пароль
            string lg = UserName.Text;
            string pas = Password.Text;
            //Получаем юзера по логину
            User res = UsrDAO.getUserByLogin(lg);
            //проверяем логин и пароль гостя
            if (res != null)
                if ((res.login == lg) & (res.pass == pas))
                {
                    CurrentUser = res.name;
                    CurrentLog = res.login;
                    Profile.uname = res.name;
                    Response.Redirect("~/TicketsForm.aspx");
                    //отправляем на главную
                }
                    //не пускаем
                else { Response.Redirect("~/Login.aspx"); }
            else { Response.Redirect("~/Login.aspx");}
        }

        //обработчик нажатия на "Clear"
        protected void cl(object sender, EventArgs e)
        {
        }
    }
}
